package com.compass.service;

import com.compass.entity.ToolRecord;
import com.compass.mapper.ToolRecordMapper;
import com.compass.util.SessionUtil;
import com.compass.vo.BaseProtocol;
import com.compass.vo.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 * User: li
 * Date: 2019/3/24
 * Time: 15:45
 * PROJECT：compass
 * PACKAGE: com.compass
 *
 * @author:55324936@qq.com To change this template use File | Settings | File Templates.
 */
@Service
@Slf4j
public class ToolRecordService {

    @Autowired
    ToolRecordMapper toolRecordMapper;

    public void record(BaseProtocol baseProtocol){
        ToolRecord toolRecord=new ToolRecord();
        BeanUtils.copyProperties(baseProtocol,toolRecord);
        try {
            LoginUser loginUser= SessionUtil.getSessionUser();
            String userName=null;
            if(null!=loginUser){
                userName=loginUser.getUserName();
            }
            toolRecord.setUserName(userName);
            int i = toolRecordMapper.record(toolRecord);
            if(0==i){
                log.error("记录工具箱调用异常");
            }
        }catch (Exception e){
            log.error("记录工具箱调用异常",e);
        }
    }
}
